﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CRMAdminDashboard
{
    public partial class FormSelectByUser : Form
    {

        #region Properties

        /// <summary>
        /// Selected SystemUser
        /// </summary>
        public SystemUser SelectedUser
        {
            get
            {
                return (SystemUser)lstUsers.SelectedItem;
            }
        }

        #endregion

        #region Entry Points

        /// <summary>
        /// Standard Constructor
        /// </summary>
        public FormSelectByUser(string helpText, RoleUserHierarchy rUHierarchy)
        {
            InitializeComponent();
            lblHelp.Text = helpText;

            // load filtered users in the list box of the dialog            
            foreach (SystemUser su in rUHierarchy.FilteredUsers.Values)
            {
                lstUsers.Items.Add(su);
            }
        }

        #endregion

        #region Local Methods

        /// <summary>
        /// Enable/disable controls accordingly
        /// </summary>
        private void EnableControls()
        {
            if (lstUsers.SelectedItems.Count > 0)
            {
                btnOK.Enabled = true;
            }
            else
            {
                btnOK.Enabled = false;
            }
        }

        #endregion

        #region Events

        private void FormSelectByUser_Load(object sender, EventArgs e)
        {
            EnableControls();
        }

        private void lstUsers_SelectedIndexChanged(object sender, EventArgs e)
        {
            EnableControls();
        }

        private void lstUsers_DoubleClick(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        #endregion

    }
}
